home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap07 / howto01 / mrodemo / mr_form.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-11  |  4.4 KB  |  163 lines

  1. unit Mr_form;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, DBGrids, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     DataSource1: TDataSource;
  12.     Table1: TTable;
  13.     DBGrid1: TDBGrid;
  14.     Table1CustNo: TFloatField;
  15.     Table1Company: TStringField;
  16.     Table1Addr1: TStringField;
  17.     Table1Addr2: TStringField;
  18.     Table1City: TStringField;
  19.     Table1State: TStringField;
  20.     Table1Zip: TStringField;
  21.     Table1Country: TStringField;
  22.     Table1Phone: TStringField;
  23.     Table1FAX: TStringField;
  24.     Table1TaxRate: TFloatField;
  25.     Table1Contact: TStringField;
  26.     Table1LastInvoiceDate: TDateTimeField;
  27.     procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  28.       Field: TField; State: TGridDrawState);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  43.   Field: TField; State: TGridDrawState);
  44. var
  45.   TextBox: TRect;
  46. begin
  47.   if Field = Table1CustNo then { Draw contents of first column }
  48.   begin
  49.     with DBGrid1.Canvas do
  50.     begin
  51.  
  52.       Font.Color := clBlack ;
  53.       Font.Name := 'MS Sans Serif' ;
  54.       Font.Size := 8 ;
  55.       Font.Style := [];
  56.  
  57.       if gdSelected in State then
  58.       begin
  59.         Font.Color := clHighlightText ;
  60.         Brush.Color := clHighlight;
  61.       end ;
  62.  
  63.       TextBox.Left := Rect.Left + 1;
  64.       TextBox.Top := Rect.Top + 1;
  65.       TextBox.Right := Rect.Right - 1;
  66.       TextBox.Bottom := Rect.Top + Abs( Font.Height ) + 3;
  67.  
  68.       TextRect( TextBox, TextBox.Left, TextBox.Top, 'Customer: ' );
  69.  
  70.       Font.Style := [ fsBold ] ;
  71.  
  72.       TextBox.Top := TextBox.Bottom + 1 ;
  73.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  74.  
  75.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Company.AsString );
  76.  
  77.       Font.Style := [ ] ;
  78.  
  79.       TextBox.Top := TextBox.Bottom + 1 ;
  80.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  81.  
  82.       TextRect( TextBox, TextBox.Left, TextBox.Top, 'Contact: ' );
  83.  
  84.       Font.Style := [ fsBold ] ;
  85.  
  86.       TextBox.Top := TextBox.Bottom + 1 ;
  87.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  88.  
  89.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Contact.AsString );
  90.  
  91.       Font.Style := [ ] ;
  92.  
  93.       TextBox.Top := TextBox.Bottom + 1 ;
  94.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  95.  
  96.       TextRect( TextBox, TextBox.Left, TextBox.Top, 'Phone: ' );
  97.  
  98.       Font.Style := [ fsBold ] ;
  99.  
  100.       TextBox.Top := TextBox.Bottom + 1 ;
  101.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  102.  
  103.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Phone.AsString );
  104.  
  105.     end ;
  106.   end
  107.   else if Field = Table1Company then { Draw contents of second column }
  108.   begin
  109.     with DBGrid1.Canvas do
  110.     begin
  111.  
  112.       Font.Color := clBlack ;
  113.       Font.Name := 'MS Sans Serif' ;
  114.       Font.Size := 8 ;
  115.       Font.Style := [];
  116.  
  117.       if gdSelected in State then
  118.       begin
  119.         Font.Color := clHighlightText ;
  120.         Brush.Color := clHighlight;
  121.       end ;
  122.  
  123.       TextBox.Left := Rect.Left + 1;
  124.       TextBox.Top := Rect.Top + 1;
  125.       TextBox.Right := Rect.Right - 1;
  126.       TextBox.Bottom := Rect.Top + Abs( Font.Height ) + 3;
  127.  
  128.       TextRect( TextBox, TextBox.Left, TextBox.Top, 'Address: ' );
  129.  
  130.       Font.Style := [ fsBold ] ;
  131.  
  132.       TextBox.Top := TextBox.Bottom + 1 ;
  133.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  134.  
  135.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Addr1.AsString );
  136.  
  137.  
  138.       TextBox.Top := TextBox.Bottom + 1 ;
  139.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  140.  
  141.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Addr2.AsString );
  142.  
  143.       TextBox.Top := TextBox.Bottom + 1 ;
  144.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  145.  
  146.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1City.AsString );
  147.       TextBox.Top := TextBox.Bottom + 1 ;
  148.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  149.  
  150.       TextRect( TextBox, TextBox.Left, TextBox.Top,
  151.         Table1State.AsString + ' ' + Table1Zip.AsString
  152.       );
  153.  
  154.       TextBox.Top := TextBox.Bottom + 1 ;
  155.       TextBox.Bottom := TextBox.Top + Abs( Font.Height) + 3;
  156.  
  157.       TextRect( TextBox, TextBox.Left, TextBox.Top, Table1Country.AsString );
  158.     end;
  159.   end;
  160. end;
  161.  
  162. end.
  163.